package com.zou.application.controller.admin;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zou.application.dao.ClassifyEntityMapper;
import com.zou.application.entity.ClassifyEntity;
import com.zou.application.utils.RandomUtils;

@Controller
@RequestMapping("/admin/classify")
public class ClassifyController {
	
	@Autowired
	private ClassifyEntityMapper classifyDao;
	
	@RequestMapping("/addClassifyPage")
	public String addClassifyPage(){
		return "/admin/classify/classify_add";
	}
	
	@RequestMapping("/addClassify")
	public String addClassify(HttpServletRequest request,ClassifyEntity classify){
		try {
			if(classify != null){
				classify.setCreater("admin");
				classify.setCreateTime(new Date());
				classify.setStatus((short)1);
				classify.setIsDelete((short)0);
				classify.setClassCode(RandomUtils.randomString(4)
						+RandomUtils.randomNumber(8));
				classifyDao.insert(classify);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "redirect:/classify/classifyList";
	}
	
	@RequestMapping("/classifyList")
	public ModelAndView classifyList(HttpServletRequest request){
		ModelAndView mv = new ModelAndView();
		Map<String, Object> param = new HashMap<String, Object>();
		List<ClassifyEntity> classifys = classifyDao.listByMap(param);
		mv.addObject("classifys",classifys);
		mv.setViewName("/admin/classify/classify_list");
		return mv;
	}
}
